Skip to content

cache compiled schema and implement cache invalidation strategy#16

Open
srivastava-diya wants to merge 11 commits into
hyperjump-io:mainfrom
srivastava-diya:feature/schema-caching
Open

cache compiled schema and implement cache invalidation strategy#16
srivastava-diya wants to merge 11 commits into
hyperjump-io:mainfrom
srivastava-diya:feature/schema-caching

Conversation

@srivastava-diya

@srivastava-diya srivastava-diya commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Description

The validate(schemaUri) function is curried calling it with just the schema URI compiles the schema and returns a reusable validator function. Previously this compilation was happening on every keystroke.

@jdesrosiers jdesrosiers left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to handle cache invalidation when a schema changes.

@srivastava-diya srivastava-diya force-pushed the feature/schema-caching branch from 0ad2b54 to 46a1d63 Compare June 15, 2026 01:09
@srivastava-diya srivastava-diya changed the title cache compiled schema validators and add id to fixtureSchemaUri in schemaValidation test cache compiled schema and implement cache invalidation strategy Jun 15, 2026
@srivastava-diya srivastava-diya force-pushed the feature/schema-caching branch from 006ca38 to 58f499e Compare June 17, 2026 21:03
Comment thread language-server/src/build-server.ts Outdated
@srivastava-diya

Copy link
Copy Markdown
Collaborator Author

hey @jdesrosiers This PR is still a WIP, so I'm not looking for approval just yet. I'd really appreciate a review to make sure if I'm proceeding in the right direction before I continue implementing the other stuff.

@jdesrosiers jdesrosiers left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're on the right track! There's some clean up and optimization we can do, but we can focus on that later after we get it working.

Comment thread language-server/src/build-server.ts Outdated
Comment thread language-server/src/build-server.ts Outdated
Comment thread language-server/src/build-server.ts Outdated
@srivastava-diya

Copy link
Copy Markdown
Collaborator Author

The PR ended up getting pretty big, so I'd appreciate a review whenever it's convenient for you.

Comment thread language-server/src/features/Diagnostics.ts Outdated
Comment thread language-server/src/features/Diagnostics.ts Outdated
Comment thread language-server/src/features/Diagnostics.ts Outdated
Comment thread language-server/src/features/Diagnostics.ts Outdated
Comment thread language-server/src/features/SchemaValidation.ts
Comment thread language-server/src/models/JsonDocument.ts Outdated
Comment thread language-server/src/models/JsonDocument.ts Outdated
Comment thread language-server/src/services/SchemaStore.ts
Comment thread language-server/src/services/SchemaStore.ts Outdated
Comment thread language-server/src/services/SchemaStore.ts Outdated
const dependentSchemaUris = this.schemaStore.getDependentSchemaUris(this.schemaUri);

if (dependentSchemaUris === undefined) {
return true;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i added true here so the document call validateSchema(), which compiles the latest schema version from disk and dependency cache can be filled.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't make sense to me. When the document is opened, it gets validated and the cache is filled. When a file changes, the only reason the dependent schemas should be undefined is if there's no schemaUri for the document. If that's the case, the document isn't dependent on any schemas and it should return false.

If I'm missing something, the best way to help me understand is to write a test that demonstrates the problem.

Comment thread language-server/src/features/SchemaValidation.ts Outdated
Comment thread language-server/src/models/JsonDocument.ts Outdated
}

private validate() {
this.parseErrors = [];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't resolved. The second case I mentioned appears to be handled, but not the first case. Write tests for both cases to make sure.

Comment on lines +23 to +36
const toClear: string[] = [];
for (const [schemaUri, compiledSchema] of this.compiledSchemaCache.entries()) {
const dependentSchemas = this.getDepsFromCompiledSchema(compiledSchema);
for (const uri of changedUris) {
if (dependentSchemas.has(uri)) {
toClear.push(schemaUri);
break;
}
}
}

for (const schemaUri of toClear) {
this.clear(schemaUri);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why collect URIs to be cleared instead of just calling clear then?

const dependentSchemaUris = this.schemaStore.getDependentSchemaUris(this.schemaUri);

if (dependentSchemaUris === undefined) {
return true;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't make sense to me. When the document is opened, it gets validated and the cache is filled. When a file changes, the only reason the dependent schemas should be undefined is if there's no schemaUri for the document. If that's the case, the document isn't dependent on any schemas and it should return false.

If I'm missing something, the best way to help me understand is to write a test that demonstrates the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants